package com.itheima.serializer;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.spring.data.connection.RedissonConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

/**
 * @program: cache
 * @description: redisson管理对象
 * @author: zhanghz001
 * @create: 2021-05-05 10:57
 **/
// @Configuration
public class ZhzRedisConfig {
    /**
     * redisson 客户端
     *
     * @return
     * @throws Exception
     */
    @Bean
    public RedissonClient redisson() throws Exception {
        ClassPathResource resource = new ClassPathResource("redisson.yml");
        Config config = Config.fromYAML(resource.getInputStream());
        RedissonClient client = Redisson.create(config);
        return client;
    }
    
    /**
     * 这个是redisson 工厂对象
     * @param redissonClient
     * @return
     */
    @Bean
    public RedissonConnectionFactory redissonConnectionFactory(RedissonClient redissonClient) {
        return new RedissonConnectionFactory(redissonClient);
    }
}
